var photoIndex = 0;

function changePhoto(command)
{
    if (command == 'first')
    {
        photoIndex = 0;
    }

    if (command == 'last')
    {
        photoIndex = fileData.length-1;
    }

    if (command == 'next')
    {
        photoIndex++;

        if (photoIndex > fileData.length-1 )
        {
            photoIndex = fileData.length-1;
        }
    }

    if (command == 'previous')
    {
        photoIndex--;

        if (photoIndex < 0)
        {
            photoIndex = 0;
        }
    }
    
    //get galleryWith from a hiddn input
    galleryWidth = document.getElementById('galleryWidth');
    
    if ( galleryWidth )
    {
    	galleryWidth = galleryWidth.value;
    }
    else
    {
    	galleryWidth = 500; //default value
    }

    var newImage 		= 'getImage.php?path='+ GALLERYPATH +'/'+fileData[photoIndex]+'&width='+galleryWidth;
    img			 		= document.getElementById('imgGaleria')
    img.src				= newImage; //troca a imagem
    img.parentNode.href = 'index.php?section=gallery&image='+fileData[photoIndex]; //cria link na imagem
    
    if (photoData[fileData[photoIndex]] == undefined)
    {
        photoData[fileData[photoIndex]] = '&nbsp;';
    }
    
    if ( element = document.getElementById('msgDiv') )
    {
    	element.innerHTML = photoData[fileData[photoIndex]];
    }
}
